package system;

import java.security.Permission;

import javax.faces.context.FacesContext;

import oracle.adf.share.ADFContext;
import oracle.adf.share.security.authorization.RegionPermission;

public class SystemSecurity {

    private boolean _authenticated;
    private String _currentUser;
    private String _displayName;

    public SystemSecurity() {
        super();
    }

    public boolean checkIsUserInRole(String roleName) {
        return (FacesContext.getCurrentInstance().getExternalContext().isUserInRole(roleName));
    }

    public boolean checkPermission(String PageDef, String Action) {
        Permission p = new RegionPermission(PageDef, Action);
        if (p != null) {
            return ADFContext.getCurrent().getSecurityContext().hasPermission(p);
        } else {
            return (false);
        }
    }

    public boolean isAuthenticated() {
        _authenticated =
                ADFContext.getCurrent().getSecurityContext().isAuthenticated();
        return _authenticated;
    }

    // ============ Current User's Name/PrincipalName =============
    public String getCurrentUser() {
        _currentUser =
                ADFContext.getCurrent().getSecurityContext().getUserName();
        return _currentUser;
    }
    
    public String getDisplayName() {
        //oracle.adf.share.security.identitymanagement.UserProfile userProfile = new oracle.adf.share.security.identitymanagement.UserProfile();
        //userProfile = ADFContext.getCurrent().getSecurityContext().getUserProfile();
        
        _displayName =
                ADFContext.getCurrent().getSecurityContext().getUserProfile().getDisplayName();
        return _displayName;
    }
}
